#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int longestArithSeqLength(const vector<int>& nums) {
    int n = nums.size();
    int ret = 2;

    unordered_map<int, int> hash;
    hash[nums[0]] = 0;

    vector<vector<int>> dp(n + 10, vector<int>(n + 10, 2));


    for (int i = 1; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            int a = 2 * nums[i] - nums[j];
            if (hash.count(a))
                dp[i][j] = dp[hash[a]][i] + 1;
            ret = max(ret, dp[i][j]);
        }
        hash[nums[i]] = i;
    }

    return ret;
}

int numberOfArithmeticSlices(vector<int>& nums) {
    int n = nums.size();

    unordered_map<long long, vector<int>> hash;
    vector<vector<long long>> dp(n + 1, vector<long long>(n));

    for (int i = 0; i < n; ++i)
    {
        hash[nums[i]].push_back(i);
    }

    long long ret = 0;

    for (int j = 2; j < n; ++j)
    {
        for (int i = 1; i < j; ++i)
        {
            long long a = (long long)nums[i] * 2 - nums[j];
            if (hash.count(a))
            {
                for (auto k : hash[a])
                {
                    if (k < i)
                    {
                        dp[i][j] += dp[k][i] + 1;
                    }
                }
            }
            ret += dp[i][j];
        }
    }

    return ret;
}

int main() 
{
    longestArithSeqLength({ 1,2,3,4,7,10 });
	
	return 0;
}